<?php

namespace app\controller\admin;

use app\BaseController;
use app\model\BalanceNotice;
use app\model\Invoice;
use app\model\Store;
use think\response\Json;

class Stores extends BaseController
{
    public function lst(): Json
    {
        return $this->success($this->app->make(Store::class)->getPage());
    }

    public function detail(): Json
    {
        return $this->success($this->app->make(Store::class)->detail());
    }

    public function save(): Json
    {
        if (!$this->request->isPost()) throw new \Exception("请求方式错误", 7001);
        return $this->success($this->app->make(Store::class)->updateOrAdd());
    }

    public function addBalance(): Json
    {
        if (!$this->request->isPost()) throw new \Exception("请求方式错误", 7001);
        return $this->success($this->app->make(Store::class)->addBalance());
    }

    public function subBalance(): Json
    {
        if (!$this->request->isPost()) throw new \Exception("请求方式错误", 7001);
        return $this->success($this->app->make(Store::class)->subBalance());
    }

    public function delete(): Json
    {
        if (!$this->request->isDelete()) throw new \Exception("请求方式错误", 7001);
        return $this->success($this->app->make(Store::class)->del());
    }

    public function storeSearch(): Json
    {
        return $this->success($this->app->make(Store::class)->getStore());
    }

    public function invoiceLst(): Json
    {
        $store_id = $this->app->make(BalanceNotice::class)->where('store_id','<>',13)->group('store_id')->column('store_id');
        return $this->success($this->app->make(Store::class)->invoiceData($store_id));
    }

    public function invoiceChat(): Json
    {
        return $this->success($this->app->make(Store::class)->invoiceChat());
    }

    public  function saveInvoice(): Json
    {
        return $this->success($this->app->make(Invoice::class)->invoiceSave());
    }

    public function invoiceLstIts(): Json
    {
        return $this->success($this->app->make(Invoice::class)->pageData());
    }

    public function invoiceDownload(): Json
    {
        $store_id = $this->app->make(BalanceNotice::class)->group('store_id')->column('store_id');
        return $this->success($this->app->make(Store::class)->invoiceDownload($store_id));
    }
}
